package com.ecoolex.hotel.saas.api.graphql;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;

import com.ecoolex.framework.modularize.api.service.storage.StorageInfo;
import com.ecoolex.framework.modularize.api.service.storage.StorageService;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.framework.web.api.graphql2.annotation.Source;
import com.ecoolex.framework.web.api.graphql2.annotation.TypeField;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module.Type;
import com.ecoolex.hotel.saas.entity.Store;
import com.ecoolex.hotel.saas.ws.StoreService;

@GraphQL2Module(type = Type.User, description = "商户")
public class StoreGraphql {

	@Reference
	private StoreService service;
	
	@Autowired
	private StorageService storageService;
	
	@TypeField(type = Store.class, field = "logo", description = { "logo" })
	public StorageInfo logo(@Source Store store) {
		return storageService.get(store.getLogo());
	}

	@TypeField(type = Store.class, field = "serviceQrCode", description = { "客服二维码" })
	public StorageInfo serviceQrCode(@Source Store store) {
		return storageService.get(store.getServiceQrCode());
	}
	
	@QueryField(field = "store", description = { "商户详情" })
	public Store store(@NonNull Integer storeId) {
		return service.getStore(storeId);
	}
}
